//
//  ViewController.swift
//  NIMSwiftTest
//
//  Created by Angus on 15/11/24.
//  Copyright © 2015年 Amazing. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    var loadingView:UIView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
  
        loadingView = UIView(frame: CGRectMake((UIScreen.mainScreen().bounds.size.width-200)/2,(UIScreen.mainScreen().bounds.size.height-200)/2,200,200));
        loadingView!.backgroundColor = UIColor.blackColor()
        loadingView!.alpha = 0.5
        
        let label:UILabel = UILabel(frame: CGRectMake((200-100)/2, (200-30)/2,100,30))
        label.textColor = UIColor.whiteColor()
        label.font = UIFont.systemFontOfSize(27)
        label.text = "Success"
        
        loadingView.addSubview(label)
    }
    
    func login(account:String!, token:String!) {
        
        self.view.addSubview(loadingView!)
        
        NIMSDK.sharedSDK().loginManager.login(account, token: token, completion: {
            [weak self](error: NSError!) ->() in
            
            if let strongSelf = self {
                
                strongSelf.loadingView?.removeFromSuperview();
                
                if error != nil {
                    print("\(error)")
                } else {
                    print(" Login success ")
                }
            }
            
        })
    }
    
    @IBAction func sessionButtonTapped(sender: AnyObject) {
        print("sessionButtonTapped ... ")
        let vc:UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("Session")
        self.navigationController?.pushViewController(vc, animated: true)
    
    }
    
 
    @IBAction func aloginButtonTapped(sender: AnyObject) {
        login("mzangus", token: "0276cbf4fbfedd53ba48720a58df77e3");
 
     
 
    }

    @IBAction func bloginButtonTapped(sender: AnyObject) {
        login("mzking", token: "0276cbf4fbfedd53ba48720a58df77e3")
    }

}

